import { get_assess_list, get_doctor_access_record_list } from '@/services/assrssment';
import {
  get_self_access_record_list,
  patient_berg_list,
  patient_depressedsds_list,
  patient_evaluation_list,
  patient_kneewomac_list,
  patient_mmrc_list,
  patient_rivermead_list,
} from '@/services/patient';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { Select, Tabs } from 'antd';
import { useEffect, useRef, useState } from 'react';
import DoctorEvaluationInfo from './components/DoctorEvaluationInfo';
import ExercisePrescriptionInfo from './components/ExercisePrescriptionInfo';
import OnlineCapacityInfo from './components/OnlineCapacityInfo';
import OnlineDepressedInfo from './components/OnlineDepressedInfo';
import OnlineRneeInfo from './components/OnlineRneeInfo';
import SelfAssessmentInfo from './components/SelfAssessmentInfo';
import OnlineBergInfo from './components/OnlineBergInfo';
import OnlineMmrcInfo from './components/OnlineMmrcInfo';
import OnlineRivermeadInfo from './components/OnlineRivermeadInfo';
type GithubIssueItem = {
  id: number;
  yiyuan: string;
  create_time: string;
  doctor: string;
  level: string;
  level_remark: string;
};
interface Iprops {
  type?: boolean;
  patientId: number | undefined;
  id_card?: string | undefined;
}
const EvaluationRecord = (props: Iprops) => {
  const { type, patientId, id_card } = props;
  const actionRef = useRef<ActionType>();
  const actionRef2 = useRef<ActionType>();
  const actionRef3 = useRef<ActionType>();
  const actionRef4 = useRef<ActionType>();
  // 医生评估详情模态框状态
  const [doctorisModalOpen, setDoctorIsModalOpen] = useState(false);
  const [doctorId, setDoctorId] = useState<number>();
  // 自我评估详情模态框状态
  const [selfisModalOpen, setSeftIsModalOpen] = useState(false);
  // 自我评估记录id
  const [selfId, setSelfId] = useState<number>();
  // 运动处方评估模态框状态
  const [exerciseisModalOpen, setExerciseIsModalOpen] = useState(false);
  const [exerciseId, setExerciseId] = useState<number>();
  // 在线评估能力评估详情模态框状态
  const [onlineCapacityModalOpen, setOnlineCapacityModalOpen] = useState(false);
  // 在线评估抑郁评估详情模态框状态
  const [onlineDepressedModalOpen, setOnlineDepressedModalOpen] = useState(false);
  // 在线评估膝关节评估详情模态框状态
  const [onlineRneeModalOpen, setOnlineRneeModalOpen] = useState(false);
  // 在线评估平衡评估详情模态框状态
  const [onlineBergModalOpen, setOnlineBergModalOpen] = useState(false);
  // 在线评估改良呼吸困难指数评估详情模态框状态
  const [onlineMmrcModalOpen, setOnlineMmrcModalOpen] = useState(false);
  // 在线评估运动指数评估详情模态框状态
  const [onlineRivermeadModalOpen, setOnlineRivermeadModalOpen] = useState(false);
  const [onlineId, setOnlineId] = useState<number>();
  // 控制在线评估下拉框的显示与隐藏
  const [status, setStatus] = useState(false);
  // 存储在线评估列表数据
  const [onlineData, setOnlineData] = useState<any>([]);
  // 存储在线评估下拉框value
  const [selectValue, setSelectValue] = useState(0);
  // 控制医生评估详情模态框的显示与隐藏
  const isShowDoctor = (status: boolean) => {
    setDoctorIsModalOpen(status);
  };
  // 控制自我评估详情模态框的显示与隐藏
  const isShowSeft = (status: boolean) => {
    setSeftIsModalOpen(status);
  };
  // 控制运动处方评估模态框的显示与隐藏
  const isShowExercise = (status: boolean) => {
    setExerciseIsModalOpen(status);
  };
  // 控制在线评估能力评估详情模态框的显示与隐藏
  const isShowCapacityOnline = (status: boolean) => {
    setOnlineCapacityModalOpen(status);
  };
  // 控制在线评估抑郁评估详情模态框的显示与隐藏
  const isShowDepressedOnline = (status: boolean) => {
    setOnlineDepressedModalOpen(status);
  };
  // 控制在线评估膝关节评估详情模态框的显示与隐藏
  const isShowRneeOnline = (status: boolean) => {
    setOnlineRneeModalOpen(status);
  };
  // 控制在线评估平衡评估详情模态框的显示与隐藏
  const isShowBergOnline = (status: boolean) => {
    setOnlineBergModalOpen(status)
  }
  // 控制在线评估改良呼吸困难指数评估详情模态框的显示与隐藏
  const isShowMmrcOnline = (status: boolean) => {
    setOnlineMmrcModalOpen(status)
  }
  // 控制在线评估运动指数评估详情模态框的显示与隐藏
  const isShowRivermeadOnline = (status: boolean) => {
    setOnlineRivermeadModalOpen(status)
  }

  // 获取医生评估列表数据
  const getDoctorList = async (params: {
    pageSize?: number | undefined;
    current?: number | undefined;
    keyword?: string | undefined;
  }) => {
    let request_body = {
      ...params,
      current: params.current,
      pageSize: params.pageSize,
      old_id: patientId,
    };
    const res = await get_doctor_access_record_list(request_body);
    console.log('医生评估记录列表', res);
    return {
      data: res.data.list,
      success: true,
      total: res.data.total_count,
    };
  };

  // 获取自我评估列表数据
  const getMySelfList = async (params: {
    pageSize?: number | undefined;
    current?: number | undefined;
    keyword?: string | undefined;
  }) => {
    let request_body = {
      ...params,
      current: params.current,
      pageSize: params.pageSize,
      old_id: patientId,
    };
    const res = await get_self_access_record_list(request_body);
    console.log('患者自我评估记录列表', res);
    return {
      data: res.data.list,
      success: true,
      total: res.data.total_count,
    };
  };
  // 默认能力评估
  useEffect(() => {
    get_patient_evaluation_list();
  }, []);

  // 在线评估能力评估列表
  const get_patient_evaluation_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    console.log('request_body', request_body);

    const res: any = await patient_evaluation_list(request_body);
    console.log('患者在线评估能力评估记录列表', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 在线评估抑郁评估列表
  const get_patient_depressedsds_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    const res: any = await patient_depressedsds_list(request_body);
    console.log('患者在线评估抑郁评估记录列表', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 在线评估膝关节评估列表
  const get_patient_kneewomac_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    const res: any = await patient_kneewomac_list(request_body);
    console.log('患者在线评估膝关节评估记录列表', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 在线评估berg平衡能力评估记录列表
  const get_patient_berg_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    const res: any = await patient_berg_list(request_body);
    console.log('患者在线评估berg平衡能力评估记录', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 在线评估bmMRC改良呼吸困难指数评估记录列表
  const get_patient_mmrc_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    const res: any = await patient_mmrc_list(request_body);
    console.log('患者在线评估mMRC改良呼吸困难指数评估记录', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 在线评估rivermead运动指数评估记录列表
  const get_patient_rivermead_list = async () => {
    let request_body = {
      id_card: id_card ?? 'null',
    };
    const res: any = await patient_rivermead_list(request_body);
    console.log('患者在线评估rivermead运动指数评估记录', res);
    if (res.code == 200) {
      setOnlineData(res.data.list);
    }
  };
  // 切换在线评估类型
  const changeOnlineType = (value: number) => {
    console.log('value', value);
    setSelectValue(value);
    if (value == 0) {
      get_patient_evaluation_list();
    }
    if (value == 1) {
      get_patient_kneewomac_list();
    }
    if (value == 2) {
      get_patient_depressedsds_list();
    }
    if (value == 3) {
      get_patient_berg_list();
    }
    if (value == 4) {
      get_patient_mmrc_list();
    }
    if (value == 5) {
      get_patient_rivermead_list();
    }
  };
  // 切换Tab
  const onChange = (key: string) => {
    if (key == '在线评估') {
      setStatus(true);
    } else {
      setStatus(false);
    }
  };
  // 医生评估
  const columns: ProColumns<GithubIssueItem>[] = [
    {
      title: '序号',
      align: 'center',
      dataIndex: 'index',
      valueType: 'index',
    },
    {
      title: '评估医生',
      align: 'center',
      dataIndex: 'platform_username',
      key: 'platform_username',
    },
    {
      title: '评估医院',
      align: 'center',
      dataIndex: 'platform_name',
      key: 'platform_name',
    },
    {
      title: '评估时间',
      align: 'center',
      key: 'create_time',
      dataIndex: 'create_time',
    },
    {
      title: '操作',
      align: 'center',
      key: 'action',
      valueType: 'option',
      render: (_, record) => (
        <a
          key="check"
          onClick={() => {
            setDoctorId(record.id);
            isShowDoctor(true);
          }}
        >
          查看
        </a>
      ),
    },
  ];
  // 自我评估
  const columns2: ProColumns<GithubIssueItem>[] = [
    {
      title: '序号',
      align: 'center',
      dataIndex: 'index',
      valueType: 'index',
    },
    {
      title: '评估等级',
      align: 'center',
      dataIndex: 'level',
      key: 'level',
    },
    {
      title: '等级说明',
      align: 'center',
      dataIndex: 'level_remark',
      key: 'level_remark',
    },
    {
      title: '评估时间',
      align: 'center',
      key: 'create_time',
      dataIndex: 'create_time',
    },
    {
      title: '操作',
      align: 'center',
      key: 'action',
      valueType: 'option',
      render: (_, record) => (
        <a
          key="check"
          onClick={() => {
            setSelfId(record.id);
            isShowSeft(true);
          }}
        >
          查看
        </a>
      ),
    },
  ];
  // 运动处方评估
  const columns3: ProColumns<GithubIssueItem>[] = [
    {
      title: '序号',
      align: 'center',
      dataIndex: 'index',
      valueType: 'index',
    },
    {
      title: '血压评估',
      align: 'center',
      dataIndex: 'xueya',
      key: 'xueya',
    },
    {
      title: '血糖评估',
      align: 'center',
      dataIndex: 'xuetang',
      key: 'xuetang',
    },
    {
      title: '体型评估',
      align: 'center',
      dataIndex: 'tixing',
      key: 'tixing',
    },
    {
      title: '评估时间',
      align: 'center',
      key: 'create_time',
      dataIndex: 'create_time',
    },
    {
      title: '操作',
      align: 'center',
      key: 'action',
      valueType: 'option',
      render: (_, record) => (
        <a
          key="check"
          onClick={() => {
            setExerciseId(record.id);
            isShowExercise(true);
          }}
        >
          查看
        </a>
      ),
    },
  ];
  // 在线评估
  const columns4: ProColumns<GithubIssueItem>[] = [
    {
      title: '序号',
      align: 'center',
      dataIndex: 'index',
      valueType: 'index',
    },
    {
      title: '评估驿站',
      align: 'center',
      dataIndex: 'poststation_name',
      key: 'poststation_name',
    },
    {
      title: '评估时间',
      align: 'center',
      key: 'create_time',
      dataIndex: 'create_time',
    },
    {
      title: '操作',
      align: 'center',
      key: 'action',
      valueType: 'option',
      render: (_, record) => (
        <>
          {selectValue == 0 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowCapacityOnline(true);
              }}
            >
              查看
            </a>
          )}
          {selectValue == 1 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowRneeOnline(true);
              }}
            >
              查看
            </a>
          )}
          {selectValue == 2 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowDepressedOnline(true);
              }}
            >
              查看
            </a>
          )}
          {selectValue == 3 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowBergOnline(true);
              }}
            >
              查看
            </a>
          )}
          {selectValue == 4 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowMmrcOnline(true);
              }}
            >
              查看
            </a>
          )}
          {selectValue == 5 && (
            <a
              key="check"
              onClick={() => {
                setOnlineId(record.id);
                isShowRivermeadOnline(true);
              }}
            >
              查看
            </a>
          )}
        </>
      ),
    },
  ];
  return (
    <div style={{ position: 'relative' }}>
      <Tabs
        type="card"
        defaultActiveKey="医生评估"
        onChange={onChange}
        items={
          type
            ? [
              {
                key: '医生评估',
                label: '医生评估',
                children: (
                  <ProTable
                    columns={columns}
                    actionRef={actionRef}
                    request={async (params = {}, sort, filter) => getDoctorList(params)}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
              {
                key: '自我评估',
                label: '自我评估',
                children: (
                  <ProTable
                    columns={columns2}
                    actionRef={actionRef2}
                    request={async (params = {}, sort, filter) => getMySelfList(params)}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
              {
                key: '运动处方评估',
                label: '运动处方评估',
                children: (
                  <ProTable
                    columns={columns3}
                    actionRef={actionRef3}
                    //   request={async (params = {}, sort, filter) => get_assessmentlist(params)}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
              {
                key: '在线评估',
                label: '在线评估',
                children: (
                  <ProTable
                    columns={columns4}
                    actionRef={actionRef4}
                    dataSource={onlineData}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
            ]
            : [
              {
                key: '医生评估',
                label: '医生评估',
                children: (
                  <ProTable
                    columns={columns}
                    actionRef={actionRef}
                    request={async (params = {}, sort, filter) => getDoctorList(params)}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
              {
                key: '自我评估',
                label: '自我评估',
                children: (
                  <ProTable
                    columns={columns2}
                    actionRef={actionRef}
                    request={async (params = {}, sort, filter) => getMySelfList(params)}
                    rowKey={(record) => record.id}
                    search={false}
                    toolBarRender={false}
                    size="middle"
                    pagination={{
                      pageSize: 10,
                      showSizeChanger: false,
                    }}
                    dateFormatter="string"
                  />
                ),
              },
            ]
        }
      />
      {status ? (
        <Select
          style={{ width: 200, position: 'absolute', top: '3px', left: '400px' }}
          onChange={changeOnlineType}
          defaultValue={0}
          options={[
            { label: '能力评估', value: 0 },
            { label: '膝关节评估', value: 1 },
            { label: '抑郁自评评估', value: 2 },
            { label: '平衡评估', value: 3 },
            { label: '改良呼吸困难指数评估', value: 4 },
            { label: '运动指数评估', value: 5 },
          ]}
        ></Select>
      ) : (
        ''
      )}

      {/* 医生评估详情 */}
      {doctorisModalOpen ? (
        <DoctorEvaluationInfo
          doctorisModalOpen={doctorisModalOpen}
          isShowDoctor={isShowDoctor}
          doctorId={doctorId}
        ></DoctorEvaluationInfo>
      ) : (
        ''
      )}
      {/* 自我评估详情 */}
      {selfisModalOpen ? (
        <SelfAssessmentInfo
          selfisModalOpen={selfisModalOpen}
          isShowSeft={isShowSeft}
          selfId={selfId}
        ></SelfAssessmentInfo>
      ) : (
        ''
      )}
      {/* 运动处方评估详情 */}
      {exerciseisModalOpen ? (
        <ExercisePrescriptionInfo
          exerciseisModalOpen={exerciseisModalOpen}
          isShowExercise={isShowExercise}
          exerciseId={exerciseId}
        ></ExercisePrescriptionInfo>
      ) : (
        ''
      )}
      {/* 在线评估能力评估详情 */}
      {onlineCapacityModalOpen ? (
        <OnlineCapacityInfo
          onlineCapacityModalOpen={onlineCapacityModalOpen}
          isShowCapacityOnline={isShowCapacityOnline}
          onlineId={onlineId}
        ></OnlineCapacityInfo>
      ) : (
        ''
      )}
      {/* 在线评估膝关节评估详情 */}
      {onlineRneeModalOpen ? (
        <OnlineRneeInfo
          onlineRneeModalOpen={onlineRneeModalOpen}
          isShowRneeOnline={isShowRneeOnline}
          onlineId={onlineId}
        ></OnlineRneeInfo>
      ) : (
        ''
      )}
      {/* 在线评估抑郁评估详情 */}
      {onlineDepressedModalOpen ? (
        <OnlineDepressedInfo
          onlineDepressedModalOpen={onlineDepressedModalOpen}
          isShowDepressedOnline={isShowDepressedOnline}
          onlineId={onlineId}
        ></OnlineDepressedInfo>
      ) : (
        ''
      )}
      {/* 在线评估平衡评估详情 */}
      {onlineBergModalOpen ? (
        <OnlineBergInfo
          onlineBergModalOpen={onlineBergModalOpen}
          isShowBergOnline={isShowBergOnline}
          onlineId={onlineId}
        ></OnlineBergInfo>) : (
        ''
      )}
      {/* 在线评估改良呼吸困难指数评估详情 */}
      {onlineMmrcModalOpen ? (
        <OnlineMmrcInfo
          onlineMmrcModalOpen={onlineMmrcModalOpen}
          isShowMmrcOnline={isShowMmrcOnline}
          onlineId={onlineId}
        ></OnlineMmrcInfo>) : (
        ''
      )}
      {/* 在线评估运动指数评估详情 */}
      {onlineRivermeadModalOpen ? (
        <OnlineRivermeadInfo
          onlineRivermeadModalOpen={onlineRivermeadModalOpen}
          isShowRivermeadOnline={isShowRivermeadOnline}
          onlineId={onlineId}
        ></OnlineRivermeadInfo>) : (
        ''
      )}
    </div>
  );
};
export default EvaluationRecord;
